﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace Dropbox.DataHouse.Logic
{
    public static class VsCodeHandler
    {
        static string[] foldersToDelete = new string[] { "bin", "obj", "debug", "release" };

        public static void DeleteVsUnusfulDirs(string dir)
        {
            DeleteFolder(new DirectoryInfo(dir), foldersToDelete, true);
        }

        public static void DeleteFolder(DirectoryInfo rootPath, IEnumerable<string> subFolderNames, bool recursive)
        {

            List<string> formattedNames = new List<string>();
            foreach (var subFolder in subFolderNames)
            {
                formattedNames.Add(subFolder.ToLower());
            }

            foreach (var subDir in rootPath.EnumerateDirectories())
            {
                if (formattedNames.Contains(subDir.Name.ToLower()))
                {
                    subDir.Delete(true);
                }
                else if (recursive)
                {
                    DeleteFolder(subDir, formattedNames, true);
                }
            }
        }

    }
}
